function doSuccess(res){
    if(res==null){
    	alert('出错了，请刷新页面重新尝试!');
		return;
    }
    if(typeof res.data.loginUrl!='undefined' && res.data.loginUrl!=''){
    	top.location.href	= res.data.loginUrl;
    }
    clearErrors('div', 'error-info');
    
    //清空错误输入框的样式
    $('.st-error-input').each(function(i,o){
    	$(o).removeClass('st-error-input');
    });
    var l		= 0;
    if(typeof res.data.error_messages!='undefined'){
    	for(var name in res.data.error_messages){
    		for(var msgname in res.data.error_messages[name]){
    			var obj = $('#'+name+'-input');
    			if(obj.is('input') || obj.is('textarea')){
    				obj.addClass('st-error-input');
    			}
    			setTextMsg(name+"-info",res.data.error_messages[name][msgname]);
    			break;
    		}
    		l++;
    	}
    }
    
    if(l==0){
    	if(typeof successFun!='undefined'){
    		successFun(res);
    	}
    }
}

function doError(res){
	alert(res.responseText);
}

function doingEdit(){

}

function setTextMsg(id,msg){
	document.getElementById(id).innerHTML	= msg;
}

function clearErrors(tagName,etype){
	var arr		= document.getElementsByTagName(tagName);
	for(var i=0,l = arr.length;i<l;i++){
		var	e	= arr[i];
		if(e.attributes['etype']!=undefined && e.attributes['etype'].nodeValue==etype){
			e.innerHTML	= '';
		}
	}
}

function doLogin(){
	$('#spLoginInfo').html('');
	var username	= $('#txtUsername').val();
	var password	= $('#txtPassword').val();
	var loginUrl	= $('#hdLoginUrl').val();
	
	$('#spLoginInfo').html('正在登录...');
	
	$.ajax({
	    url: loginUrl,
	    type: 'POST',
	    data:{'username':username,'password':password,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code<=0){
				$('#spLoginInfo').html('登录失败，请检查你的输入！');
			}else{
				document.location	= res.data.forward;
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

//确认返利
function checkReturn(id,status){
	var hideUrl	= $('#hdHideUrl').val();
	$.ajax({
	    url: hideUrl,
	    type: 'POST',
	    data:{'id':id,'status':status,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				document.location.reload();
			}else if(res.code==400){
				alert('可返利金额不足，操作失败！');
			}else{
				alert('获取记录失败，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function category(pid,hdId){
	url = $('#hdCategoryUrl').val();
	$.ajax({
	    url: url,
	    type: 'GET',
	    data:{'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
	    	var multiSelect		= new MultiSelect(pid,hdId,res.data.categories.dataMultiCategory,res.data.categories.dataAllCategory);
	    	multiSelect.init();
	    	multiSelect.select($('#'+hdId).val());
		},
		error:function(res){
			alert('加载类目出错，请刷新页面重新加载');
		}
	});
}